package com.lnt.spring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @title :
 * @createDate : 2021-10-26 09:40
 * @creater : LuNanTing
 * @className : UserService
 */
@Component("userService")
public class UserService {

    @Autowired
    private OrderService orderService;

    @Autowired
    private JdbcTemplate jdbcTemplate;


//    @Value("张三")
//    private User user;

    /**
     * 如果此时的构造函数的参数是其他bean，在Spring初始化该bean对象时，会去Spring bean对象池中去找改参数对象
     * ————>查找的时候会根据：①先通过Type，即通过类查找，如果这个类定义了多个bean对象，则进行第②步，否则返回当前找到的对象；
     * ————>②然后会通过变量名查找,如果定义了多个相同类型的不同name 的bean对象，当name不存在则会抛出异常
     *
     */
//    public UserService(OrderService orderService){
//        this.orderService = orderService;
//        System.out.println("orderService ");
//    }

    public void a(){
        System.out.println("userService's method:a");
    }

    @Transactional
    public void b(){
        jdbcTemplate.execute("insert into test1 values (1,1,1,1,1)");
//        userService.c();
    }

    @Transactional(propagation = Propagation.NEVER)
    public void c() throws DataAccessException {
        jdbcTemplate.execute("insert into test1 values (2,2,2,2,2)");
    }

    public void user(){
//        System.out.println("====将JDK自带的类型转换PropertyEditor纳入Spring容器====");
//        System.out.println(user);
    }
}
